package FlowGram.Application.Parser.Controllers;

import java.awt.Color;


/**
 * 
 * @author thackray
 *
 */
public class FinchConsoleController extends FinchController{

	protected enum Direction{
		North, South, East, West
	}
	
	protected int maxX;
	protected int maxY;
	
	protected int positionx;
	protected int positiony;
	protected Direction direction;
	
	public FinchConsoleController(){
		this.direction = Direction.North;
		this.positionx = this.positiony = 0;
		this.maxX = this.maxY = 10;
	}
	
	public String getName(){
		return "FinchConsoleController";
	}
	
	public void resetState(){
		this.positionx = this.positiony = 0;
		this.direction = Direction.North;
	}
	
	@Override
	public void moveForward() {
		switch(this.direction){
			case North:
				this.positiony += 1;
				break;
			case South:
				this.positiony -= 1;
				break;
			case East:
				this.positionx += 1;
				break;
			case West:
				this.positionx -= 1;
				break;
		}
		System.out.println("Controller: moving forward");
		this.statePosition();
	}

	@Override
	public void turnLeft() {
		switch(this.direction){
			case North:
				this.direction = Direction.West;
				break;
			case South:
				this.direction = Direction.East;
				break;
			case East:
				this.direction = Direction.North;
				break;
			case West:
				this.direction = Direction.South;
				break;
		}
		System.out.println("Controller: turning left");
		this.statePosition();
	}

	@Override
	public void turnRight() {
		switch(this.direction){
			case North:
				this.direction = Direction.East;
				break;
			case South:
				this.direction = Direction.West;
				break;
			case East:
				this.direction = Direction.South;
				break;
			case West:
				this.direction = Direction.North;
				break;
		}
		System.out.println("Controller: turning right");
		this.statePosition();
	}
	
	public void setColor(Color c){
		System.out.println("Controller: setting color to ("+c.getRed()+","+c.getGreen()+","+c.getBlue()+")");
	}
	public void setColor(Color c, int time){
		System.out.println("Controller: setting color to ("+c.getRed()+","+c.getGreen()+","+c.getBlue()+")");
	}
	
	protected void statePosition(){
		System.out.print("Controller: position = ("+this.positionx+", "+this.positiony+") facing ");
		switch(this.direction){
			case North:
				System.out.print("north");
				break;
			case South:
				System.out.print("south");
				break;
			case East:
				System.out.print("east");
				break;
			case West:
				System.out.print("west");
				break;
		}
		System.out.println();
	}

	@Override
	public boolean isBlocked() {
		System.out.print("Controller: checking if blocked: ");
		if(Math.abs(this.positionx) >= maxX || Math.abs(this.positiony) >= maxY){
			System.out.println("Yes");
			return true;
		}
		System.out.println("No");
		return false;
	}

	@Override
	public boolean isTapped() {
		return false;
	}

	@Override
	public void chirp(int frequency, int duration) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isOnBeeper() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void pickBeeper() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void putBeeper(Color c) {
		// TODO Auto-generated method stub
		
	}
}
